package com.spring.xenon.web.tools;

import java.util.List;

import com.spring.xenon.web.model.Menu;

public class MenuMaker {
	
	public static String createMenu(List<Menu> al) {
		StringBuffer all = new StringBuffer("");
		for (Menu xm : al) {
			if (xm.getPid().equals("0")) {
				StringBuffer li = new StringBuffer("<li><a href='"+xm.getUrl()+"'>"
						+ "<i class='"+xm.getIcon()+"'></i>"
						+ "<span class='title'>" + xm.getName() + "</span>"
						+ "</a>");
				String cli = mlist(li, xm.getId(), al);
				li.append(cli);
				li.append("</li>");
				all.append(li);
			}
		}
		return all.toString();
	}

	public static String mlist(StringBuffer li, String id, List<Menu> al) {
		Boolean b = false;
		StringBuffer ul = new StringBuffer("<ul>");
		for (Menu xm : al) {
			if (xm.getPid().equals(id)) {
				b = true;
				StringBuffer lii = new StringBuffer("<li>"
						+ "<a href='javascript:void(0)' jsrc='" + xm.getUrl()
						+ "' onclick='jforword(this)'>"
//						+ "<i class='entypo-flow-line'></i>"
						+ "<span class='title'>" + xm.getName() + "</span>"
						+ "</a>");
				String cli = mlist(lii, xm.getId(), al);
				lii.append(cli);
				lii.append("</li>");
				ul.append(lii);
			}
		}
		ul.append("</ul>");
		if (b == true) {
			return ul.toString();
		} else {
			return "";
		}

	}

}
